package it.polimi.traveldream;

import it.polimi.traveldream.entities.Excursion;
import it.polimi.traveldream.entities.Hotel;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * Session Bean implementation class GestioneShowExcursion
 */
@Stateless
public class GestioneShowExcursion implements GestioneShowExcursionLocal {

	@PersistenceContext
    private EntityManager em;
	
    /**
     * Default constructor. 
     */
    public GestioneShowExcursion() {
        // TODO Auto-generated constructor stub
    }
    @Override
    public List<ExcursionDTO> showExcursion(){
    	Query q = em.createNamedQuery("Excursion.findAll");
    	return convert(q.getResultList());
    }
    
    public List<ExcursionDTO> convert(List<Excursion> list1){
    	List<ExcursionDTO>tmp=new ArrayList<ExcursionDTO>();
    	
    	for(Excursion e: list1){
    		ExcursionDTO etmp=new ExcursionDTO();
    		etmp.setId(e.getId());
    		etmp.setDescription(e.getDescription());
    		etmp.setDurata(e.getDurata());
    		etmp.setName(e.getName());
    		etmp.setPrice(e.getPrice());
    		
    		tmp.add(etmp);
    	}
    	
    	return tmp;
    	
    }

}
